#include "includes.h"

#define  VALUENUM  3

extern int coordinate,last_coordinate;                                  
extern int Right,Left;      

int AveragevalueSum = 0;     
int Value[VALUENUM]={0};
int Averagevalue = 0;

int   w_flag=0,z_flag=0;


void PathOperation(void)
{
  int i = 0;   
  int k = VALUENUM-2;  
    
  //w_flag=0;
  AveragevalueSum  -= Value[VALUENUM-1];   

  for( i=0;i<VALUENUM-1;i++ ) 
  {                          //更新队列表 
    Value[k+1]=Value[k] ;
    k--;
  }
  Value[0] =coordinate;                 
  AveragevalueSum  += Value[0];
  Averagevalue  = (int)(AveragevalueSum/VALUENUM);      //最近的连续 10 次偏离平均值
 
  if(abs(Averagevalue)<20) 
  {
    w_flag=0; 
    z_flag++;      
  }
  
  /*if((abs(Averagevalue)>10)||(abs(Value[0]>15)&&abs(Value[0])>abs(Value[1])&&abs(Value[1])>abs(Value[2])&&z_flag>20)) //&&Value[2]>Value[3]  //入弯
  {
    w_flag=1; 
    z_flag=0; 
  }
  
  if(abs(Value[0]<15)&&abs(Value[0])<abs(Value[1])&&abs(Value[1])<abs(Value[2]))    //&&Value[2]<Value[3]  //出弯
   {
    w_flag=2;
    z_flag=0;
   } */
} 

void pathfilter(void) 
{
  static int coordinate0,coordinate1,coordinate2,coordinate3;
     {  
         coordinate3=128-Left-Right;
         
         coordinate1=coordinate0;
         coordinate0=coordinate3;
         coordinate=(int)((2*coordinate0+coordinate1+coordinate2)/3);
     }   
}